<template>
  <div class="materialReturnBill">
    <div class="publicSearch">
      <div class="searchBar" :style="{ height: isMoreSearch ? 'auto' : '' }">
        <el-button-group>
          <el-button @click="getmaterialReturnBillData" size="mini" icon="el-icon-search">查询</el-button>
          <el-button @click="clearSearchData" size="mini" icon="el-icon-refresh">重置</el-button>
        </el-button-group>
        <div>
          <span>入库单明细号</span>
          <el-input v-model="searchData.asnDetailNo" size="mini" placeholder="入库单明细号" clearable></el-input>
        </div>
        <!-- <div>
          <span>采购单明细号</span>
          <el-input
            v-model="searchData.requestDetailDetailNo"
            size="mini"
            placeholder="采购单明细号"
            clearable
          ></el-input>
        </div> -->
        <div>
          <span>物料名称</span>
          <el-input v-model="searchData.itemName" size="mini" placeholder="物料名称" clearable></el-input>
        </div>
        <div>
          <span>物料编码</span>
          <el-input v-model="searchData.itemCode" size="mini" placeholder="物料编码" clearable></el-input>
        </div>
        <div>
          <span>关键字搜索</span>
          <el-input
            v-model="searchData.keyWords"
            size="mini"
            title="批次名称/验收人/追踪号/货位编码/包装"
            placeholder="批次名称/验收人/追踪号/货位编码/包装"
            clearable
          ></el-input>
        </div>
      </div>
    </div>

    <div class="tableBox">
      <el-table
        v-loading="loading.masterTable"
        highlight-current-row
        :data="materialReturnBills"
        style="width: 100%"
      >
        <el-table-column fixed="left" type="index" width="50"></el-table-column>
        <!-- <el-table-column
                sortable
                show-overflow-tooltip
                prop="billType"
                label="验收类型"
                width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.billType === 1" type="success">采 购</span>
            <span v-else-if="scope.row.billType === 2" type="">asn</span>
            <span v-else-if="scope.row.billType === 3" type="info">盲 收</span>
          </template>
        </el-table-column>-->
        <el-table-column
          sortable
          show-overflow-tooltip
          prop="acceptRecordCode"
          label="收货单号"
          width="150"
        ></el-table-column>
        <el-table-column sortable show-overflow-tooltip prop="state" label="状态" width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.state == 0" style="color: #409eff">初始化</span>
            <span v-if="scope.row.state == 2" style="color: #67c23a">已确认</span>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip prop="qcState" label="质检状态" width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.qcState == 0" style="color: #409eff">免检</span>
            <span v-if="scope.row.qcState == 1" style="color: #409eff">待检</span>
            <span v-if="scope.row.qcState == 2" style="color: #67c23a">已检</span>
            <span v-if="scope.row.qcState == 3" style="color: #faa755">让步</span>
            <span v-if="scope.row.qcState == 4" style="color: #d71345">不合格</span>
          </template>
        </el-table-column>
        <el-table-column
          sortable
          show-overflow-tooltip
          prop="organizationName"
          label="货主"
          width="120"
        >
          <template slot-scope="scope">
            <span
              class="textBtn"
              @click="
                $EventBus.$emit(
                  'showPublicModal',
                  scope.row.organizationId,
                  'organization'
                )
              "
            >{{ scope.row.organizationName }}</span>
          </template>
        </el-table-column>
        <el-table-column sortable show-overflow-tooltip prop="itemName" label="物料名称" width="160">
          <template slot-scope="scope">
            <span
              class="textBtn"
              @click="
                $EventBus.$emit('showPublicModal', scope.row.itemCode, 'item')
              "
            >{{ scope.row.itemName }}</span>
          </template>
        </el-table-column>
        <el-table-column sortable show-overflow-tooltip prop="itemCode" label="物料编码" width="160">
          <template slot-scope="scope">
            <span
              class="textBtn"
              @click="
                $EventBus.$emit('showPublicModal', scope.row.itemCode, 'item')
              "
            >{{ scope.row.itemCode }}</span>
          </template>
        </el-table-column>
        <el-table-column sortable show-overflow-tooltip prop="batchName" label="批次" width="100"></el-table-column>
        <el-table-column show-overflow-tooltip prop="quantity" label="数量" width="80">
          <!-- <template slot-scope="scope">
                  <span >{{scope.row.quantity}}（主单位）</span>
          </template>-->
        </el-table-column>
        <!-- <el-table-column
              
                show-overflow-tooltip
                prop="packDescribe"
                label="验收包装"
                width="80">
        </el-table-column>-->
        <el-table-column sortable show-overflow-tooltip prop="cellCode" label="货位编码" width="120"></el-table-column>
        <el-table-column sortable show-overflow-tooltip prop="boxCode" label="追踪号" width="120"></el-table-column>
        <el-table-column
          sortable
          show-overflow-tooltip
          prop="acceptUserName"
          label="验收人"
          width="100"
        >
          <template slot-scope="scope">
            <span
              class="textBtn"
              @click="
                $EventBus.$emit(
                  'showPublicModal',
                  scope.row.acceptUserId,
                  'account'
                )
              "
              type="text"
            >{{ scope.row.acceptUserName }}</span>
          </template>
        </el-table-column>
        <el-table-column sortable show-overflow-tooltip prop="acceptTime" label="收货时间" width="120">
          <template slot-scope="scope">{{ scope.row.acceptTime.substr(5, 11) }}</template>
        </el-table-column>
        <!-- <el-table-column
                sortable
                show-overflow-tooltip
                prop="requestDetailDetailNo"
                label="采购单明细号"
                width="130">
        </el-table-column>-->
        <el-table-column
          sortable
          show-overflow-tooltip
          prop="asnDetailNo"
          label="入库单明细号"
          width="130"
        >
          <template slot-scope="scope">
            <span
              class="textBtn"
              @click="
                $router.push({
                  name: 'asnBillDetail',
                  params: { billNo: scope.row.asnBillNo },
                })
              "
            >{{ scope.row.asnDetailNo }}</span>
          </template>
        </el-table-column>

      </el-table>
      <el-pagination
        class="pagination-bottom"
        style="text-align: right"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="searchData.pageNum"
        :page-sizes="[15, 30, 50, 100]"
        :page-size="searchData.pageSize"
        layout="sizes,total, prev, pager, next"
        :total="searchData.total"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  name: "materialReturnBill",
  data() {
    // 校验规则
    return {
      isMoreSearch: false,
      loading: {
        masterTable: true
      },
      // 用作查询的数据
      searchData: {
        pageNum: 1,
        pageSize: 15,
        total: null,
        keyWords: "",
        wareId: PF.getLocal("wareId", "number"),
        itemCode: "",
        itemName: "",
        organizationId: null,
        asnDetailNo: "",
        requestDetailDetailNo: "",
        billType: ""
      },
      searchStates: [
        {
          value: "enable",
          label: "启用"
        },
        {
          value: "disable",
          label: "禁用"
        }
      ],
      //存放装箱单数据的数组
      materialReturnBills: [],
      form: {
        //
      },
      rules: {
        //
      },
      formLabelWidth: "120px",
      rowData: {
        //
      },
      Mystyle: { height: "50px" },
      filterText: "",
      defaultProps: {
        children: "children",
        label: "name"
      },
      roleRowInfo: {
        //
      },
      roleForm: {
        //
      },
      roleRules: {
        //
      },
      tableRowClassName({ row, rowIndex }) {
        if (row.accountStatus === "disable") {
          return "disable-row";
        } else if (row.accountStatus === "enable") {
          return "enable-row";
        }
        return "";
      }
    };
  },
  computed: {},
  watch: {
    //
  },
  methods: {
    //分页设置每页的条数
    handleSizeChange(val) {
      this.searchData.pageSize = val;
      this.getmaterialReturnBillData();
    },
    //分页设置从第几条开始
    handleCurrentChange(val) {
      this.searchData.pageNum = val;
      this.getmaterialReturnBillData();
    },
    // 清空查询条件
    clearSearchData() {
      this.searchData.keyWords = "";
      this.searchData.itemCode = "";
      this.searchData.itemName = "";
      this.searchData.organizationId = "";
      this.searchData.asnDetailNo = "";
      this.searchData.requestDetailDetailNo = "";
      this.searchData.billType = "";
    },
    //根据筛选条件查询数据
    getmaterialReturnBillData() {
      let that = this;
      that.loading.masterTable = true;
      let searchData = JSON.parse(JSON.stringify(this.searchData));
      IOT.getServerData("/accept/records/materialReturn/list", "get", searchData, ret => {
        that.loading.masterTable = false;
        if (ret.code === 200) {
          // rows就是返回的数据
          this.materialReturnBills = ret.rows;
          this.searchData.total = ret.total;
          this.searchData.pageNum = ret.pageNumber;
        } else {
          IOT.tips(ret.message || "服务器请求失败，稍后再试！", "error");
        }
      });
    }
  },
  // 页面加载时刷新
  created() {
    // this.searchData.pageNum = 1;
    // this.searchData.pageSize = 10;
    //请求数据
    this.getmaterialReturnBillData();
  }
};
</script>

<style scoped lang="less">
.materialReturnBill {
}
</style>
